package com.xiguanlezz.cn.server.codec;

import com.xiguanlezz.cn.common.RequestMessage;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageDecoder;

import java.util.List;

/**
 * @Author：习惯了种种
 * @CreateDate：2024/10/16 22:21
 * @Description：将ByteBuf解码为业务Java对象的解码器，此处是服务端，接收到的Java业务对象为客户端发来的RequestMessage
 */
public class OrderProtocolDecoder extends MessageToMessageDecoder<ByteBuf> {
    @Override
    protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, List<Object> outList) throws Exception {
        RequestMessage requestMessage = new RequestMessage();
        requestMessage.decode(byteBuf);
        // decode完后需要加入到outList上
        outList.add(requestMessage);
    }
}
